<template>
    <div id="app">
        <el-container>
            <el-aside width="200px">
                <div id="logo-box">
                    <img id="logo" src="@/assets/logo.png" alt=""/>
                    <p id="kuangjia-xitong">武藏学校管理系统</p>

                </div>
                <router-link to="/index">
                    <div id="shouye">
                        <img id="shouye-img" src="@/assets/系统管理.png" alt=""/>
                        <span slot="title"> 系统首页</span>
                    </div>
                </router-link>
                <el-menu
                        :default-active="$route.path"
                        class="el-menu-vertical-demo"
                        @open="handleOpen"
                        @close="handleClose"
                        background-color="rgb(21, 60, 101)"
                        text-color="#fff"
                        active-text-color="#ffd04b"
                >
                    <el-submenu index="2">
                        <template slot="title">
                            <img src="@/assets/教师管理.png" alt=""/>
                            <span slot="title"> 教师管理</span>
                        </template>
                        <el-menu-item-group>
                            <router-link to="/teacherList">
                                <el-menu-item index="/teacherList">教师列表</el-menu-item>
                            </router-link>
                            <router-link to="/addTeacher">
                                <el-menu-item index="/addTeacher">新增教师</el-menu-item>
                            </router-link>
                        </el-menu-item-group>
                    </el-submenu>

                    <el-submenu index="3">
                        <template slot="title">
                            <img src="@/assets/学生管理.png" alt=""/>
                            <span slot="title"> 学生管理</span>
                        </template>
                        <el-menu-item-group>
                            <router-link to="/Student">
                                <el-menu-item index="/Student">所有学生</el-menu-item>
                            </router-link>
                            <router-link to="/newStudent">
                                <el-menu-item index="/newStudent">新增学生</el-menu-item>
                            </router-link>
                        </el-menu-item-group>
                    </el-submenu>

                    <el-submenu index="4">
                        <template slot="title">
                            <img src="@/assets/课程管理.png" alt=""/>
                            <span slot="title"> 课程管理</span>
                        </template>
                        <el-menu-item-group>
                            <router-link to="/course1">
                                <el-menu-item index="/course1">课程列表</el-menu-item>
                            </router-link>
                            <router-link to="/AddCourse">
                                <el-menu-item index="/AddCourse">新增课程</el-menu-item>
                            </router-link>
                        </el-menu-item-group>
                    </el-submenu>

                    <el-submenu index="5">
                        <template slot="title">
                            <img src="@/assets/图书管理.png" alt=""/>
                            <span slot="title"> 图书管理</span>
                        </template>
                        <el-menu-item-group>
                            <router-link to="/BooksList">
                                <el-menu-item index="/BooksList">所有图书</el-menu-item>
                            </router-link>
                            <router-link to="/AddBook">
                                <el-menu-item index="/AddBook">新增图书</el-menu-item>
                            </router-link>
                        </el-menu-item-group>
                    </el-submenu>

                    <el-submenu index="6">
                        <template slot="title">
                            <img src="@/assets/部门管理.png" alt=""/>
                            <span slot="title"> 部门管理</span>
                        </template>
                        <el-menu-item-group>
                            <router-link to="/departmentList">
                                <el-menu-item index="/departmentList">部门列表</el-menu-item>
                            </router-link>
                            <router-link to="/addDepartment">
                                <el-menu-item index="/addDepartment">新增部门</el-menu-item>
                            </router-link>
                        </el-menu-item-group>
                    </el-submenu>

                    <el-submenu index="7">
                        <template slot="title">
                            <img src="@/assets/管理员.png" alt=""/>
                            <span slot="title"> 管理员管理</span>
                        </template>
                        <el-menu-item-group>
                            <router-link to="/administrator">
                                <el-menu-item index="/administrator">管理员列表</el-menu-item>
                            </router-link>
                            <router-link to="/addAdmin">
                                <el-menu-item index="/addAdmin">新增管理员</el-menu-item>
                            </router-link>
                        </el-menu-item-group>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-container>
                <el-header id="kuangjia-head">
                    <div id="mytime">{{gettime}}</div>
                    <el-button
                            :plain="true"
                            id="logout-button"
                            type="info"
                            @click="logout"
                    >退出登录
                    </el-button>
                    <div id="kuangjia-touxiang">
                        <img id="user-img" :src="imgUrl" alt=""/>
                    </div>
                    <p id="kuangjia-username">{{username}}</p>
                </el-header>

                <el-main>
                    <router-view/>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>


<script>
    export default {
        data() {
            return {
                imgUrl: '',
                isCollapse: false,
                gettime: '',//获取的当前的时间
                token: "",//当前登录账号的token
                username: '请登录'
            };
        },
        methods: {
            handleOpen(key, keyPath) {
                console.log(key, keyPath);
            },
            handleClose(key, keyPath) {
                console.log(key, keyPath);
            },
            setTime() {
                setInterval();
            },
            logout() {
                this.$confirm("此操作将退出登录，确定退出？", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                })
                    .then(() => {
                        this.$axios({
                            url: '/logout',
                            params: {token: this.token}
                        }).then((res) => {
                            this.$message({
                                type: "success",
                                message: "退出成功!",
                            });
                            this.$router.push("/login");
                        })
                    }).catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消",
                    });
                });
            },
            getTime: function () {
                var _this = this;
                let yy = new Date().getFullYear();
                let mm = new Date().getMonth() + 1;
                let dd = new Date().getDate();
                let hh = new Date().getHours();
                let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
                let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
                _this.gettime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss;
            },
            currentTime() {
                setInterval(this.getTime, 500)
            },
        },
        mounted() {
            this.$axios({
                url: '/manager/findManagerByToken',
                params: {
                    token: sessionStorage.token
                }
            }).then((res) => {
                this.username = res.data.data.managerName;
                this.imgUrl = res.data.data.imageUrl;
            })
        },
        created() {
            this.currentTime();
        }
    };
</script>
<style>
    #kuangjia-head {
        line-height: 60px !important;
    }
</style>
<style scoped>
    * {
        margin: 0;
        padding: 0;
    }

    .el-menu-vertical-demo:not(.el-menu--collapse) {
        width: 200px;
        min-height: 400px;
    }

    .template {
        height: 100%;
    }

    a {
        text-decoration: none;
    }

    .el-container {
        height: 100%;
    }

    #logo-box {
        width: 200px;
        height: 120px;
    }

    #kuangjia-head {
        background-color: #b3c0d1;
        color: #333;
        line-height: 80px;
    }

    .el-menu {
        border-right: none;
    }

    #shouye-img {
        margin-top: 16px;
        margin-left: 23px;
    }

    .el-aside,
    #logo-box,
    #kuangjia-head {
        background: rgb(21, 60, 101);
    }

    #logo {
        width: 80px;
        height: 60px;
        margin-left: 50px;
        margin-top: 10px;
    }

    #kuangjia-xitong {
        text-align: center;
        color: white;
        font-size: 18px;
    }

    span,
    .el-menu-item {
        color: white;
        font-size: 14px;
    }

    #kuangjia-btn {
        font-size: 40px;
        color: white;
    }

    #kuangjia-touxiang {
        width: 40px;
        height: 40px;
        border: white solid 1px;
        border-radius: 50%;
        float: right;
        background: white;
        margin-right: 5px;
        margin-top: 9px;

    }

    #logout-button {
        float: right;
        margin-top: 10px;
        width: 100px;
    }

    #user-img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
    }

    a.el-icon-search {
        font-size: 15px;
    }

    .el-input {
        width: 300px;
        margin-left: 30px;
    }

    #kuangjia-username {
        float: right;
        color: white;
        margin-right: 5px;
    }

    #shouye {
        width: 200px;
        height: 56px;
        background: rgb(21, 60, 101);
    }

    #mytime {
        float: left;
        font-size: 22px;
        color: white;
    }

</style>
<style lang="less">
    html,
    body,
    #app {
        height: 100%;
        margin: 0;
    }
</style>

